package exam;

import java.util.ArrayList;
import java.util.Collections;

public class demo01 {
    public int findKth(int[] a, int n, int K) {
        // write code here
        ArrayList <Integer> l = new ArrayList ();
        for (int i = 0; i < a.length; i++) {
            l.add(a[i]);
        }

        Collections.sort(l);

        int newIndex = l.size() -1;
        while (K>1){
            int temp = l.get(newIndex);
            newIndex --;
            while (l.get(newIndex) == temp){
                newIndex --;
            }
            K = K -1;
        }
        return l.get(newIndex);
    }
}
